Skip to content

publish: return api.ErrCanceled when user declines interactive prompts#13674

Merged
glours merged 3 commits intodocker:mainfrom
ishwar170695:fix/publish-aborted-sentinel-error-v2
Mar 31, 2026
Merged

publish: return api.ErrCanceled when user declines interactive prompts#13674
glours merged 3 commits intodocker:mainfrom
ishwar170695:fix/publish-aborted-sentinel-error-v2

Conversation

@ishwar170695
Copy link
Copy Markdown
Contributor

@ishwar170695 ishwar170695 commented Mar 26, 2026

What I did

Previously, declining the bind mount or sensitive data warning prompt caused publish() to return nil, which is indistinguishable from success for callers and automation scripts (exit code 0).

Change publish() to return the existing api.ErrCanceled sentinel so callers can detect user-initiated cancellation via errors.Is(). Add unit tests covering both the preChecks decline path and the full publish() path.

Signed-off-by: Ishwar chand meena [email protected]

(not mandatory) A picture of a cute animal, if possible in relation to what you did

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes compose publish to return a detectable error when the user declines interactive safety prompts, instead of returning nil (success), so automation/callers can distinguish an abort from a successful publish.

Changes:

  • Introduce a new sentinel error (ErrPublishAborted) and return it when pre-check prompts are declined.
  • Add unit tests intended to cover “decline” paths for preChecks and publish.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/compose/publish.go Returns a sentinel error when publish is aborted via interactive decline.
pkg/compose/publish_test.go Adds tests for decline behavior in pre-checks and publish.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ishwar170695 ishwar170695 changed the title publish: return ErrPublishAborted when user declines interactive prompts publish: return api.ErrCanceled when user declines interactive prompts Mar 26, 2026
@ishwar170695
Copy link
Copy Markdown
Contributor Author

Updated PR description to reflect the use of the existing api.ErrCanceled instead of creating a new custom error.

Copy link
Copy Markdown
Contributor

@glours glours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution 🙏
I have small requests before we can merge it

}, cmp.Ignore()))
}

func Test_preChecks_decline_returns_ErrPublishAborted(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn’t any ErrPublishedArboted error in the codebase, so the test name is misleading.
Second, this test is effectively a subset of Test_publish_decline_returns_ErrCanceled.

We can keep it, but I’d suggest repurposing it to cover the sensitive data detection path instead. That would make it exercise an uncovered code path and give it a clearer purpose.

@ishwar170695
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I've repurposed the test to cover the checkForSensitiveData + decline path using a temp .env file with a dummy AWS secret key. The test name is updated to reflect what it actually tests.

@glours
Copy link
Copy Markdown
Contributor

glours commented Mar 31, 2026

@ishwar170695 can you sing-off your commits please

glours
glours previously approved these changes Mar 31, 2026
Copy link
Copy Markdown
Contributor

@glours glours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glours glours enabled auto-merge (rebase) March 31, 2026 14:00
@glours
Copy link
Copy Markdown
Contributor

glours commented Mar 31, 2026

@ishwar170695 CI detected tests which need to be changed to check properly the new 130 exit code
And there is some lint issues to fix also

Renames test to Test_preChecks_sensitive_data_detected_decline. Uses a temporary .env file with an AWS token to reliably trigger the DefangLabs secret detector, and confirms that preChecks correctly aborts early on user decline.

Signed-off-by: Ishwar <[email protected]>
auto-merge was automatically disabled March 31, 2026 16:27

Head branch was pushed to by a user without write access

@ishwar170695 ishwar170695 force-pushed the fix/publish-aborted-sentinel-error-v2 branch from c8d190e to df5d68b Compare March 31, 2026 16:27
@ishwar170695
Copy link
Copy Markdown
Contributor Author

Sorry for disabling auto-merge, the force-push after rebase triggered that.
Addressed the lint issue (gofumpt on publish_test.go), updated e2e tests to expect exit code 130 for the decline paths, and rebased cleanly onto main. Ready for re-review when you get a chance.

@glours glours enabled auto-merge (rebase) March 31, 2026 16:59
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@glours glours merged commit 1e3f4d0 into docker:main Mar 31, 2026
102 of 124 checks passed
@ishwar170695 ishwar170695 deleted the fix/publish-aborted-sentinel-error-v2 branch April 1, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants